package name.zxw.rabbitmq.workqueues;

import com.rabbitmq.client.Channel;
import name.zxw.rabbitmq.util.RabbitMqUtils;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @author ZhangXinWang
 * @date 2022/5/19 8:05
 */
public class Task01 {

    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtils.getChannel();
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String message = scanner.next();
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            System.out.println("发送消息完成:" + message);

//            channel.basicAck();//用于肯定确认
//            channel.basicNack();//用于否定确认
//            channel.basicReject();//用否定确认,比basicNack少一个参数, 不处理该消息直接拒绝了,可以将其丢弃



        }

    }


}
